{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目1\n",
    "\n",
    "我使用dict结构储存好友通讯录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n"
     ]
    }
   ],
   "source": [
    "book = {\"Alice\":\"123\",\"Bob\":\"134\"}\n",
    "print(book[\"Alice\"])"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25]\n"
     ]
    }
   ],
   "source": [
    "a_list=[1,2,3,4,5]\n",
    "square_list = [value**2 for value in a_list] \n",
    "print(square_list)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rock crushes scissors. Scissors cut paper. Paper covers rock.\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "choices = ['rock', 'paper', 'scissors']\n",
    "print('Rock crushes scissors. Scissors cut paper. Paper covers rock.')\n",
    "player = input('Do you want to be rock, paper or scissors (or quit)?')\n",
    "\n",
    "while player != 'quit':\n",
    "    computer = random.randint(0,2)\n",
    "    player = choices.index(player)\n",
    "    if computer == player:\n",
    "        print(\"电脑出的%s，平局\"% choices[computer])\n",
    "    elif computer == player+1 or (computer==2 and player==0):\n",
    "        print(\"电脑出的%s，你输了\"% choices[computer])\n",
    "    else:\n",
    "        print(\"电脑出的%s，你赢了\"% choices[computer])\n",
    "    player = input('Do you want to be rock, paper or scissors (or quit)?')\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目5、6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "黑猫跳了2步\n",
      "黑猫说：“喵，你好”\n",
      "黑猫说：“你好”\n"
     ]
    }
   ],
   "source": [
    "class cat:\n",
    "    def __init__(self,color):\n",
    "        self.color = color\n",
    "    def jump(self, num):\n",
    "        print(\"%s猫跳了%d步\"%(self.color,num))\n",
    "    def speak(self, str):\n",
    "        print(\"%s猫说：“%s”\"%(self.color,str))\n",
    "\n",
    "cat1 = cat(\"黑\")\n",
    "cat1.jump(2)\n",
    "\n",
    "class BlackCat(cat):\n",
    "    def __init__(self):\n",
    "        super().__init__(\"黑\")\n",
    "    \n",
    "    def speak(self, str):\n",
    "        print(\"%s猫说：“喵，%s”\"%(self.color,str))\n",
    "\n",
    "cat2 = BlackCat()\n",
    "cat2.speak(\"你好\")\n",
    "super(BlackCat,cat2).speak(\"你好\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch+py39",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.15"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "0c2909dd695fccec19105365a9f990beaa0038c1ef55b005c1656fc62b9f85f8"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
